package com.bw.yk02.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public class IkanalyzerUtil {
    public static List<String> getIkanalyzer(String text) {
        List<String> list = new ArrayList<String>();

        if(text!=null)
        {
            StringReader sr = new StringReader(text);
            IKSegmenter ik = new IKSegmenter(sr, true);

            try{
                Lexeme le= ik.next();
                while(le!=null)
                {
                    list.add(le.getLexemeText());
                    le=ik.next();
                }

            }catch(Exception e)
            {
                e.printStackTrace();
            }
        }
        return list;
    }

    public static void main(String[] args) {
        IkanalyzerUtil ik = new IkanalyzerUtil();
        List<String> list = ik.getIkanalyzer("我爱北京天安门");
        for(int i=0;i<list.size();i++)
            System.out.println(list.get(i));
    }
}
